<template>
  <div class="box">
    <div class="Info">
      <img
        v-if="commentData.user.head_img"
        :src="$axios.defaults.baseURL + commentData.user.head_img"
        alt=""
        class="avatar"
      />
      <img v-else src="@/assets/default.png" alt="" class="avatar" />
      <div class="middle">
        <div class="name">{{ commentData.user.nickname }}</div>
        <div class="date">22小时前</div>
      </div>
      <div class="replay" @click="sendComment">回复</div>
    </div>
    <Parent :parentData="commentData.parent" v-if="commentData.parent" />
    <div class="mainContent">
      {{ commentData.content }}
    </div>
  </div>
</template>

<script>
import Parent from "./Parent";
import eventBus from "../../utils/eventBus";
export default {
  props: ["commentData"],
  components: {
    Parent,
  },
  methods: {
    sendComment() {
      // 用$emit监听触发事件
      eventBus.$emit("sendMsg", this.commentData.id);
    },
  },
};
</script>

<style lang="less" scoped>
.box {
  padding: 10/360 * 100vw;
  border-bottom: 1px solid #e4e4e4;
  .Info {
    display: flex;
    align-items: center;
    .avatar {
      width: 35/360 * 100vw;
      height: 35/360 * 100vw;
      border-radius: 50%;
      object-fit: cover;
    }
    .middle {
      flex-grow: 1;
      padding-left: 10/360 * 100vw;
      .name {
        font-size: 16/360 * 100vw;
        color: #333;
      }
      .date {
        font-size: 12/360 * 100vw;
        color: #888;
      }
    }
    .replay {
      font-size: 14/360 * 100vw;
      color: #555;
    }
  }
  .mainContent {
    font-size: 16/360 * 100vw;
    color: #333;
    padding-top: 10/360 * 100vw;
  }
}
</style>